home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Special 23
/
AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso
/
PublicDomain
/
Anwendungen
/
db3.6-beta-src
/
dbGUI.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-03-14
|
48KB
|
1,113 lines
/*
* GUI Designed by : David Ekholm, Datadosen
*/
#include <stdlib.h> /* atoi() */
#include <exec/types.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <intuition/screens.h> /* DrawInfo */
#include <intuition/classes.h>
#include <intuition/classusr.h>
#include <intuition/imageclass.h>
#include <intuition/gadgetclass.h>
#include <gadgets/textfield.h>
#include <intuition/sghooks.h> /* struct SGWork here */
#include <workbench/workbench.h> /* For AppWindow */
#include <libraries/gadtools.h>
#include <libraries/commodities.h> /* This has a nice qualifier #define */
#include <libraries/iffparse.h>
#include <graphics/displayinfo.h>
#include <graphics/gfxbase.h>
#include <graphics/text.h> /* For my TextAttr struct */
#include <graphics/rastport.h>
#include <utility/hooks.h> /* For my stringhook */
#include <proto/wb.h> /* For AppWindow */
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/graphics_protos.h>
#include <clib/utility_protos.h>
#include <string.h>
#include <pragmas/exec_pragmas.h>
#include <pragmas/intuition_pragmas.h>
#include <pragmas/gadtools_pragmas.h>
#include <pragmas/graphics_pragmas.h>
#include <pragmas/utility_pragmas.h>
#include <proto/textfield.h>
#include "dbGUI.h"
#include "db.h"
#include "dbparser.h"
#include "Version.h"
#define TOGGLE_LED *(UBYTE *)0xbfe001 ^= 2
extern Class *TextFieldClass;
extern struct IFFHandle *Iff0;
struct Screen *Scr = NULL;
struct DrawInfo *DrInfo = NULL;
UWORD *Pens;
APTR VisualInfo = NULL;
struct IntuiMessage DB_Msg;
UWORD DB_Zoom[4];
struct Gadget *LastGad = NULL;
struct Hook MyStrHook;
struct TextAttr *Font, Attr;
UWORD FontX, FontY;
UWORD OffX, OffY;
UWORD DragKnobWidth, DragKnobHeight;
WORD LastLeftEdge=-1;
WORD LastTopEdge=-1; /* For nice layoutswitching */
/*For gadgetlayout */
UWORD TabSize;
/* For MyStrHookFunc() */
BOOL ReactivateGad = FALSE;
BOOL GadDoubleClicked = FALSE;
struct Gadget *NextGad = NULL;
struct TextAttr UserTextAttr =
{
NULL, 0, FS_NORMAL, FPF_DISKFONT
};
struct NewMenu DB_NewMenu[] = {
NM_TITLE, (STRPTR)MSG_PROJECT_MENU , NULL, 0, NULL, NULL,
NM_ITEM, (STRPTR)MSG_PROJECT_NEW , NULL, 0, 0L, (APTR)DB_NEW,
NM_ITEM, (STRPTR)MSG_PROJECT_OPEN , NULL, 0, 0L, (APTR)DB_OPEN,
NM_ITEM, (STRPTR)MSG_PROJECT_RELOAD, NULL, 0, 0L, (APTR)DB_RELOAD,
NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
NM_ITEM, (STRPTR)MSG_PROJECT_SAVE , NULL, 0, 0L, (APTR)DB_SAVE,
NM_ITEM, (STRPTR)MSG_PROJECT_SAVE_AS, NULL, 0, 0L, (APTR)DB_SAVEAS,
NM_ITEM, (STRPTR)MSG_PROJECT_OUTPUT , NULL, 0, NULL,NULL,
NM_SUB, (STRPTR)MSG_PROJECT_OUTPUT_VIEW, NULL, 0, 0L, (APTR)DB_OUTPUT_VIEW,
NM_SUB, (STRPTR)MSG_PROJECT_OUTPUT_VIEW_WN, NULL, 0, 0L, (APTR)DB_OUTPUT_VIEW_WN,
NM_SUB, (STRPTR)MSG_PROJECT_OUTPUT_TAB_ASCII, NULL, 0, 0L, (APTR)DB_OUTPUT_TAB_ASCII,
NM_SUB, (STRPTR)MSG_PROJECT_OUTPUT_COMMA_ASCII, NULL, 0, 0L, (APTR)DB_OUTPUT_COMMA_ASCII,
NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
NM_ITEM, (STRPTR)MSG_PROJECT_ABOUT, NULL, 0, 0L, (APTR)DB_ABOUT,
NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
NM_ITEM, (STRPTR)MSG_PROJECT_QUIT, NULL, 0, 0L, (APTR)DB_QUIT,
NM_TITLE, (STRPTR)MSG_EDIT_MENU, NULL, 0, NULL, NULL,
NM_ITEM, (STRPTR)MSG_EDIT_CUT, NULL, 0, 0L, (APTR)DB_CUT,
NM_ITEM, (STRPTR)MSG_EDIT_COPY, NULL, 0, 0L, (APTR)DB_COPY,
NM_ITEM, (STRPTR)MSG_EDIT_PASTE, NULL, 0, 0L, (APTR)DB_PASTE,
NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
NM_ITEM, (STRPTR)MSG_EDIT_ADD, NULL, 0, 0L, (APTR)DB_ADD,
NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
NM_ITEM, (STRPTR)MSG_EDIT_KILL, NULL, 0, 0L, (APTR)DB_KILL,
NM_TITLE, (STRPTR)MSG_VIEW_MENU, NULL, 0, NULL, NULL,
NM_TITLE, (STRPTR)MSG_ACTION_MENU, NULL, 0, NULL, NULL,
NM_ITEM, (STRPTR)MSG_ACTION_FIND, NULL, 0, 0L, (APTR)DB_FIND,
NM_ITEM, (STRPTR)MSG_ACTION_FIND_NEXT, NULL, 0, 0L, (APTR)DB_FINDNEXT,
NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
NM_ITEM, (STRPTR)MSG_ACTION_SORT, NULL, 0, 0L, (APTR)DB_SORT,
NM_ITEM, (STRPTR)MSG_ACTION_DIAL, NULL, 0, 0L, (APTR)DB_DIAL,
NM_ITEM, (STRPTR)MSG_ACTION_BROWSE, NULL, 0, 0L, (APTR)DB_BROWSE,
NM_TITLE, (STRPTR)MSG_SETTINGS_MENU, NULL, 0, NULL, NULL,
NM_ITEM, (STRPTR)MSG_SETTINGS_WARNINGS, NULL, CHECKIT|CHECKED|MENUTOGGLE, 0L, (APTR)DB_WARNINGS,
NM_ITEM, (STRPTR)MSG_SETTINGS_SORTDIR, NULL, 0, NULL, NULL,
NM_SUB, (STRPTR)MSG_SETTINGS_SORTDIR_AZ, NULL, CHECKIT|CHECKED, 2L, (APTR)DB_AZ,
NM_SUB, (STRPTR)MSG_SETTINGS_SORTDIR_ZA, NULL, CHECKIT, 1L, (APTR)DB_ZA,
NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
NM_ITEM, (STRPTR)MSG_SETTINGS_FIELD_DEFINITION, NULL, NM_ITEMDISABLED, 0L, (APTR)DB_FIELD_DEFINITION,
NM_ITEM, (STRPTR)MSG_SETTINGS_VIEW_DESIGN, NULL, 0L, 0L, (APTR)DB_VIEW_DESIGN,
NM_TITLE, (STRPTR)MSG_AREXX_MENU, NULL, 0, NULL, NULL,
NM_ITEM, (STRPTR)MSG_AREXX_EXECUTE, NULL, 0, 0L, (APTR)DB_EXECUTE_AREXX,
NM_ITEM, (STRPTR)MSG_AREXX_EXECUTE_RELAUNCH, NULL, 0, 0L, (APTR)DB_EXECUTE_AREXX_AGAIN,
NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
NM_END, NULL, NULL, 0, 0L, NULL };
void LocalizeMenu(struct NewMenu *nm)
{
/* Replaces the string-indexes in the NewMenu array with localized text */
/* Gets called once from SetupScreen() */
UWORD i=0;
while (nm[i].nm_Type != NM_END) {
if (nm[i].nm_Label != NM_BARLABEL) {
nm[i].nm_CommKey = GetAppStr((LONG)nm[i].nm_Label);
nm[i].nm_Label = nm[i].nm_CommKey+2;
if (nm[i].nm_CommKey[0] == ' ') nm[i].nm_CommKey = NULL;
}
++i;
}
}
/**/
__inline BOOL OkStrGad(struct Gadget *g)
{
return (BOOL)(g->Flags & GFLG_TABCYCLE && !(g->Flags & GFLG_DISABLED));
}
struct Gadget *PrevStrGad(struct Gadget *Gad, struct Gadget *glist)
{
/* Returns the previous stringgadget, or NULL if Gad is the first one */
struct Gadget *strgad = NULL, *g = glist;
if (g == Gad) return NULL;
for (; g; g = g->NextGadget) {
if (OkStrGad(g)) strgad = g; /* Only return stringgads */
if (g->NextGadget == Gad) break;
}
return strgad;
}
struct Gadget *EndGad(struct Gadget *g)
{
while (g->NextGadget) g = g->NextGadget;
return g;
}
struct Gadget *ActivateThisGad(ULONG actions, struct Gadget *current,
struct Gadget *glist)
{
/* Takes over the job of deciding which (if any) gadget should be reactivated
* based upon the SGWork->Actionfield.
* Without this function, it is impossible to activate other stringgadgets
* (as responce to an ARexx command) as Intiuition otherwize will have
* activated some other gadget first if the user cyclesteps thru a gadgetlist.
*/
struct Gadget *g = NULL;
if (actions & SGA_NEXTACTIVE) {
for (g = current->NextGadget;; g = g->NextGadget) {
if (!g) g = glist;
if (OkStrGad(g)) break;
}
}
else if (actions & SGA_PREVACTIVE) {
for (g = PrevStrGad(current, glist);; g = PrevStrGad(g, glist)) {
if (!g) g = EndGad(glist);
if (OkStrGad(g)) break;
}
}
return g;
}
/* Stuff for my stringHook */
ULONG __saveds __asm MyStrHookFunc(register __a0 struct Hook *hook,
register __a2 struct SGWork *sgw,